package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.VO.AlbumListItemVO;
import cn.tedu.csmall.product.pojo.VO.AlbumStandardVO;
import cn.tedu.csmall.product.pojo.VO.AttributeTemplateListVO;
import cn.tedu.csmall.product.pojo.VO.AttributeTemplateStandardVO;
import cn.tedu.csmall.product.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmall.product.pojo.dto.AttributeTemplateAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AttributeTemplateUpdateDTO;
import cn.tedu.csmall.product.service.IAttributeTemplateService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/attribute-template")
@Api(tags = "属性模板管理模块")
@Validated
public class AttributeTemplateController {
    @Autowired
    IAttributeTemplateService attributeTemplateService;
    @PostMapping("/add-new")
    @ApiOperation("添加属性模板")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@Valid AttributeTemplateAddNewDTO attributeTemplateAddNewDTO){
        attributeTemplateService.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("根据id删除属性模板")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> delete(@Range(min = 1,max = 10000,message = "删除相册失败，相册ID非法！") @PathVariable Long id){
        attributeTemplateService.deleteById(id);
        return JsonResult.ok();
    }
    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改属性模板")
    @ApiOperationSupport(order = 300)
    public JsonResult<Void> updateInfoById(@PathVariable Long id, AttributeTemplateUpdateDTO attributeTemplateUpdateDTO){
        attributeTemplateService.updateInfoById(id, attributeTemplateUpdateDTO);
        return JsonResult.ok();
    }
    @GetMapping("/select")
    @ApiOperation("查询属性模板")
    @ApiOperationSupport(order = 400)
    public JsonResult<List<AttributeTemplateListVO>> select(){
        List<AttributeTemplateListVO> list = attributeTemplateService.list();
        return JsonResult.ok(list);
    }
    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据ID查看属性模板")
    @ApiOperationSupport(order = 500)
    public JsonResult<AttributeTemplateStandardVO> getStandardById(@PathVariable Long id) {
        AttributeTemplateStandardVO standardById = attributeTemplateService.getStandardById(id);
        return JsonResult.ok(standardById);
    }
}
